package com.luotao.test.hbase.domain;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-28
 * Time: 17:28
 */
public class RowCounter {
    static final String NAME = "rowcounter";

    static class RowCounterMapper extends TableMapper<ImmutableBytesWritable, Result> {
        public static enum Counters {ROWS}

        public void map(ImmutableBytesWritable row, Result values,
                        Context context) throws IOException {
            for (KeyValue value : values.list()) {
                if (value.getValue().length > 0) {
                    context.getCounter(Counters.ROWS).increment(1);
                    break;
                }
            }
        }
    }


}
